package com.study.compose.beta.view

import android.app.Activity
import android.os.Bundle
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.module.compose.base.composable.Content
import com.module.compose.base.composable.ContentView
import com.module.compose.base.composable.Title
import com.module.compose.base.utils.goTo
import com.study.compose.beta.activity.SampleActivity

@Composable
fun ListSample() {
    val context = LocalContext.current as Activity
    LazyColumn(
        Modifier
            .fillMaxSize()
            .padding(start = 15.dp, end = 15.dp)
    ) {
        item {
            Column(horizontalAlignment = Alignment.CenterHorizontally) {
                ContentView {
                    Title(title = "介绍")
                    Content(
                        isNeedScroll = false,
                        content =
                        """
                        可使用verticalScroll()修饰Column实现滚动，但是系统会对所有列表项进行组合和布局,无论他们是否可见，因此需要显示大量列表项时，会带来性能问题。
                        
                        Compose提供了一组组件，这些组件只会对在窗口中可见的列表项进行组合和布局，这些组件包括LazyColumn 和 LazyRow。
                        """.trimIndent()
                    )
                }

                Button(
                    onClick = {
                        val bundle = Bundle()
                        bundle.putString("title", "LazyColumn")
                        context.goTo(SampleActivity::class.java, bundle = bundle)
                    },
                    Modifier.width(180.dp),
                ) {
                    Text(text = "LazyColumn")
                }
                Spacer(modifier = Modifier.height(15.dp))
                Button(
                    onClick = {
                        val bundle = Bundle()
                        bundle.putString("title", "LazyRow")
                        context.goTo(SampleActivity::class.java, bundle = bundle)
                    },
                    Modifier.width(180.dp),
                ) {
                    Text(text = "LazyRow")
                }
            }
        }
    }
}